#import "FlutterPlugin_aPlugin.h"

@implementation FlutterPlugin_aPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"flutter_plugin_a:flutter_call_native"
            binaryMessenger:[registrar messenger]];
  FlutterPlugin_aPlugin* instance = [[FlutterPlugin_aPlugin alloc] init];
  [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  if ([@"getPlatformVersion" isEqualToString:call.method]) {
    result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  } else if ([@"addInteger" isEqualToString:call.method]) {
      id arguments = call.arguments;
      NSInteger a = 0;
      NSInteger b = 0;
      if ([arguments isKindOfClass:[NSArray class]] && [arguments count] == 2) {
          a = [arguments[0] integerValue];
          b = [arguments[1] integerValue];
      }

      NSInteger ret = [self addInteger:a b:b];
      result([NSNumber numberWithInteger:ret]);
  } else if([@"getDicInfo" isEqualToString:call.method]) {
       NSDictionary *dicInfo = [self getDicInfo];
       result(dicInfo);
  }  else if([@"getArrayInfo" isEqualToString:call.method]) {
        NSArray *arrInfo = [self getArrayInfo];
        result(arrInfo);
  } else {
    result(FlutterMethodNotImplemented);
  }
}

#pragma method
- (NSInteger)addInteger:(NSInteger)a b:(NSInteger)b {
    return (a + b);
}

- (NSDictionary *)getDicInfo {
    return @{
        @"name": @"zhangsan",
        @"age": @20,
    };
}

- (NSArray *)getArrayInfo {
    return @[
        @"hello",
        @"baby",
        @25
    ];
}

@end
